<template>
  <div class="func-comp-form">

    <ComponentGlobalSettingForm :id="id" :compConfigData="compConfigData"></ComponentGlobalSettingForm>

    <Tabs name="main_tabs" size="small" v-model="mainTabsValue">
      <TabPane name="main_tab" tab="main_tabs" label="主配置">

        <Form :label-width="120">

          <FormItem label="最大值">
            <InputNumber size="small" :max="10000000" :min="-10000000" v-model="max"></InputNumber>
          </FormItem>
          <FormItem label="最小值">
            <InputNumber size="small" :max="10000000" :min="-10000000" v-model="min"></InputNumber>
          </FormItem>
          <FormItem label="跳跃步伐">
            <Tooltip content="每次改变的步伐，可以是小数" placement="left">
              <InputNumber size="small" :max="10000000" :min="0" v-model="step"></InputNumber>
            </Tooltip>
          </FormItem>
          <FormItem label="尺寸">
            <Select :transfer="true" size="small" v-model="size">
              <Option v-for="item in sizes" :value="item.value" :key="item.value">{{ item.label }}</Option>
            </Select>
          </FormItem>
          <FormItem label="默认值">
            <InputNumber size="small" v-model="defaultValue"/>
          </FormItem>
          <FormItem label="占位文本">
            <Input size="small" v-model="placeholder"/>
          </FormItem>
          <FormItem label="是否可手动编辑">
            <i-switch v-model="editable"></i-switch>
          </FormItem>
          <FormItem label="实时响应数据">
            <Tooltip content="是否实时响应数据，设置为false时，只会在失焦时更改数据" :max-width="200" placement="left">
              <i-switch v-model="activeChange"></i-switch>
            </Tooltip>
          </FormItem>

          <FormItemPanel title="样式配置">
            <FormItem label="放大倍率">
              <Tooltip content="可将组件进行等比例放大" placement="left">
                <InputNumber size="small" :max="10" :min="0" :step="0.1" v-model="inputStyle.scaleValue" :active-change="false"></InputNumber> 倍
              </Tooltip>
            </FormItem>
            <FormItem label="宽度">
              <Input size="small" v-model="inputStyle.width"/>
            </FormItem>
            <FormItem label="背景色">
              <PnColorPicker size="small" v-model="inputStyle.backgroundColor" alpha recommend/>
            </FormItem>
            <FormItem label="文本色">
              <PnColorPicker size="small" v-model="inputStyle.color" alpha recommend/>
            </FormItem>
            <FormItem label="边框颜色">
              <PnColorPicker size="small" v-model="inputStyle.borderColor" alpha recommend/>
            </FormItem>
          </FormItemPanel>
        </Form>

      </TabPane>
      <TabPane name="interaction_tab" tab="main_tabs" label="交互">
        <Container v-if="mainTabsValue == 'interaction_tab'">
          <CustomJsDocument></CustomJsDocument>
          <FormItemPanel title="初始化运行脚本">
            <CodeEditor v-model="customGlobalJsCode"></CodeEditor>
          </FormItemPanel>
          <FormItemPanel title="选中值变化时触发">
            <InteractionSender :interactionKey="'itemChange'" :canAddFieldsMap="false"></InteractionSender>
            <Alert show-icon>通过value可获取选中值</Alert>
            <CodeEditor v-model="onChangeCode"></CodeEditor>
          </FormItemPanel>
        </Container>
      </TabPane>
    </Tabs>

  </div>
</template>

<script>

  import FuncCompFormMixin from '@/mixin/FuncCompFormMixin'

  import { createHelpers } from 'vuex-map-fields';

  const { mapFields } = createHelpers({
    getterType: 'designer/getLayoutItem',
    mutationType: 'designer/updateLayoutItem',
  });

  export default {
    name: 'InputNumberCompForm', // 此名称必须填写，且必须与组件文件名相同，并且必须加上Form字符
    mixins: [FuncCompFormMixin],
    data() {
      return {
        sizes: [
          {label: '默认', value: 'default'},
          {label: '小尺寸', value: 'small'},
          {label: '大尺寸', value: 'large'},
        ]
      }
    },
    mounted() {

    },
    methods: {},
    computed: {
      ...mapFields({

        max: 'component.compConfigData.max',
        min: 'component.compConfigData.min',
        step: 'component.compConfigData.step',
        size: 'component.compConfigData.size',
        placeholder: 'component.compConfigData.placeholder',
        editable: 'component.compConfigData.editable',
        activeChange: 'component.compConfigData.activeChange',
        defaultValue: 'component.compConfigData.defaultValue',

        inputStyle: 'component.compConfigData.inputStyle',

        onChangeCode: 'component.compConfigData.onChangeCode'

      })
    }
  }
</script>

<style scoped>

</style>
